<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>AngelScript: The variable parameter type</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
</script>


</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">AngelScript
   
   </div>
   
  </td>
  
  
  
   
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.7.5.1 -->
</div>
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
  initNavTree('doc_adv_var_type.html','');
</script>
<div id="doc-content">
<div class="header">
  <div class="headertitle">
<div class="title">The variable parameter type </div>  </div>
</div>
<div class="contents">
<div class="textblock"><p>The application can register functions that take a reference to a variable type, which means that the function can receive a reference to a variable of any type. This is useful when making generic containers.</p>
<p>When a function is registered with this special parameter type, the function will receive both the reference and an extra argument with the type id of the variable type. The reference refers to the actual value that the caller sent, i.e. if the expression is an object handle then the reference will refer to the handle, not the actual object.</p>
<div class="fragment"><pre class="fragment"><span class="comment">// An example usage with a native function</span>
engine-&gt;<a class="code" href="classas_i_script_engine.html#a754fafd069d8e0c19baff2dc222893b0" title="Registers a global function.">RegisterGlobalFunction</a>(<span class="stringliteral">&quot;void func_c(?&amp;in)&quot;</span>, <a class="code" href="angelscript_8h.html#a78f8f2c7f1c88b12e74a5ac47b4184ae" title="Returns an asSFuncPtr representing the function specified by the name.">asFUNCTION</a>(func_c), <a class="code" href="angelscript_8h.html#a3ec92ea3c4762e44c2df788ceccdd1e4a68ae43cc91cdfc3fa4590c9e6164e4f4" title="A cdecl function.">asCALL_CDECL</a>);

<span class="keywordtype">void</span> func_c(<span class="keywordtype">void</span> *ref, <span class="keywordtype">int</span> typeId)
{
    <span class="comment">// Do something with the reference</span>

    <span class="comment">// The type of the reference is determined through the type id</span>
}

<span class="comment">// An example usage with a generic function</span>
engine-&gt;<a class="code" href="classas_i_script_engine.html#a754fafd069d8e0c19baff2dc222893b0" title="Registers a global function.">RegisterGlobalFunction</a>(<span class="stringliteral">&quot;void func_g(?&amp;in)&quot;</span>, <a class="code" href="angelscript_8h.html#a78f8f2c7f1c88b12e74a5ac47b4184ae" title="Returns an asSFuncPtr representing the function specified by the name.">asFUNCTION</a>(func_g), <a class="code" href="angelscript_8h.html#a3ec92ea3c4762e44c2df788ceccdd1e4a750c26b6a6e0c9ccbb93078f532ef8ce" title="A function using the generic calling convention.">asCALL_GENERIC</a>);

<span class="keywordtype">void</span> func_g(<a class="code" href="classas_i_script_generic.html" title="The interface for the generic calling convention.">asIScriptGeneric</a> *gen)
{
    <span class="keywordtype">void</span> *ref = gen-&gt;<a class="code" href="classas_i_script_generic.html#ac5c73473ccefe029582c5e3793d1a41b" title="Returns the address held in a reference or handle argument.">GetArgAddress</a>(0);
    <span class="keywordtype">int</span> typeId = gen-&gt;<a class="code" href="classas_i_script_generic.html#a3539887ace8f4dcf6a4dcb202afd10d3" title="Returns the type id of the argument.">GetArgTypeId</a>(0);

    func_c(ref, typeId);
}
</pre></div><p>The variable type can also be used with <code>out</code> references, but not with <code>inout</code> references. Currently it can only be used with global functions, object constructors, and object methods. It cannot be used with other behaviours and operators.</p>
<p>The variable type is not available within scripts, so it can only be used to register application functions.</p>
<dl class="see"><dt><b>See also:</b></dt><dd><a class="el" href="doc_addon_any.html">any object</a> and <a class="el" href="doc_addon_dict.html">dictionary object</a> for examples </dd></dl>
</div></div>
</div>
  <div id="nav-path" class="navpath">
    <ul>

    <li class="footer">Generated on Sun Jan 29 2012 15:41:03 for AngelScript by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.5.1 </li>
   </ul>
 </div>


</body>
</html>
